package com.springboot.chapter3.pojo;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 作者：paopao
 * 版本：1.0
 */
// 要启动 SpringBoot 才能看见配置属性，SpringIoC 无法读取 application.yml
//@Data
//@Component
//public class DataBaseProperties {
//    @Value("${database.driverName}")
//    private String driverName;
//    @Value("${database.url}")
//    private String url;
//    private String username;
//    private String password;
//
//    @Value("${database.username}")
//    public void setUsername(String username) {
//        System.out.println("username = " + username);
//        this.username = username;
//    }
//
//    @Value("${database.password}")
//    public void setPassword(String password) {
//        System.out.println("password = " + password);
//        this.password = password;
//    }
//}

@Data
@Component
@ConfigurationProperties("database")
public class DataBaseProperties {
    private String driverName;
    private String url;
    private String username;
    private String password;

    public void setUsername(String username) {
        System.out.println("username = " + username);
        this.username = username;
    }

    public void setPassword(String password) {
        System.out.println("password = " + password);
        this.password = password;
    }
}
